<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>姓名</button>
    <script>
        var that;
        class Star{
            constructor(name){
                that = this;
                /* constructor是一个对象 */
                 /* constructor里面的this指向的是 创建的实例对象 */
                this.girlname = name;
                this.btn = document.querySelector('button');
                this.btn.onclick = this.sing;
                console.log(this);
               
            }
            sing(){
                /* 按钮是一类对象，sing函数被btn调用后，sing里面的this就指向btn，所以girlname被控制台输出为undifined */
                /* 谁调用了这个方法就指向谁
                 */
                console.log(that.girlname);
            }
        }
        var txy = new Star('薛天宝');
        txy.sing();
    </script>
</body>
</html>